package com.ie.sevice.before;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ie.common.http.ResponseResult;
import com.ie.entity.FocusEntity;
import com.ie.mapper.before.FocusMapper;
import com.ie.mapper.before.FocusMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @classname: FocusServiceImpl
 * @Author: S2
 * @Description: //TODO
 * @Date: 2025/5/29  8:27
 * @Param:
 * @version: 1.0
 **/
@Service
public class FocusServiceImpl extends ServiceImpl<FocusMapper, FocusEntity> implements FocusService {
    @Override
    public ResponseResult<Map<String, Object>> addFocus(FocusEntity focusEntity) {
        // 查询是否已经关注该商品
        Long count = lambdaQuery().eq(FocusEntity::getGoodstableId, focusEntity.getGoodstableId())
                .eq(FocusEntity::getBusertableId, focusEntity.getBusertableId()).count();
        if (count > 0) {
            return ResponseResult.getMessageResult(null, "A001");
        }
        // 添加关注
        focusEntity.setFocustime(new Date());
        if (save(focusEntity)) {
            return ResponseResult.getMessageResult(null, "A002");
        }
        return ResponseResult.getMessageResult(null, "A003");
    }
}
